package inutan.game.condition;

import inutan.game.event.model.RoleLevelUpEvent;
import inutan.game.condition.task.RoleLevelUpCondition;
import org.ricks.common.event.IEvent;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 条件以lambda封装，以枚举维护进map
 */
public class ConditionManager {

    final static Map<Class<? extends IEvent>, Condition> conditionsMap = new HashMap<>();

    static {
        ConditionEnum.values();
    }

    enum ConditionEnum {
        ROLE_LEVEL_UP(RoleLevelUpEvent.class, new RoleLevelUpCondition()),
        Get_MAIL_ID(RoleLevelUpEvent.class, new RoleLevelUpCondition());

        private Class<? extends IEvent> eventKlass;

        private Condition conditions;

        ConditionEnum(Class<? extends IEvent> eventKlass, Condition condition) {
            this.eventKlass = eventKlass;
            this.conditions = condition;
            conditionsMap.put(eventKlass, condition);
        }
    }

    public static void condition(IEvent event) {
        Condition condition = conditionsMap.get(event.getClass());
        if(Objects.nonNull(condition)) {
            condition.emit(event);
        }
    }

}
